package bueu.bexl;

public class ValueExpr extends BexlExpr {

	private final Object object;
	
	public ValueExpr(final Object object) {
		super(false);
		this.object = object;
	}

	@Override
	protected final Object eval(final BexlCtx ctx, final Object current, final boolean set,
			final Object newValue) throws BexlException {
		return this.object;
	}
	
	@Override
	public final String toString() {
		if (this.object == null) {
			return "null";
		}

		if (this.object instanceof Number) {
			return this.object.toString();
		}
		
		if (this.object instanceof Boolean) {
			return ((Boolean) this.object).toString();
		}
		
		StringBuilder sb = new StringBuilder("'");
		sb.append(this.object).append("'");

		return sb.toString();
	}
}
